package com.dragons.spring5.annotation;
import com.dragons.spring5.annotation.config.SpringConfig;
import com.dragons.spring5.annotation.service.UserService1;
import com.dragons.spring5.service.UserService;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestSpringDemo1{

    @Test
    public void testAdd(){
        BeanFactory context = new ClassPathXmlApplicationContext("annotation.xml");
        UserService1 userService1=context.getBean("userService1",UserService1.class);
        System.out.println(userService1);
        userService1.add();
    }

    @Test
    public void testAdd1(){
        BeanFactory context = new ClassPathXmlApplicationContext("annotation.xml");
        UserService1 userService1=context.getBean("userService1",UserService1.class);
        userService1.normal();
    }

    @Test
    public void testService2() {
        //加载配置类
        ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        UserService1 userService1 = context.getBean("userService1", UserService1.class);
        System.out.println(userService1);
        userService1.add();
    }

}
